package com.one.group.user.controller;

import com.one.group.model.dto.RegisterDto;
import com.one.group.model.dto.SendCodeDto;
import com.one.group.model.dto.UserLoginDto;
import com.one.group.result.Result;
import com.one.group.user.service.impl.UserServiceImpl;
import com.one.group.utils.ResultUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
@Tag(name = "用户相关接口")
@Slf4j
public class UserController {
    @Autowired
    private UserServiceImpl userService;
    @PostMapping("/login")
    public Result login(@RequestBody UserLoginDto userloginDto) {
        //2.添加
        String token = userService.login(userloginDto);
        return ResultUtil.success(token);
    }
    //发送验证码
    @PostMapping("/sendCode")
    public Result sendCode(@RequestBody SendCodeDto sendCodeDto) {
        return userService.sendCode(sendCodeDto);
    }
    //注册
    @PostMapping("/register")
    public Result register(@RequestBody RegisterDto registerDto) {
        return userService.register(registerDto);
    }
}
